/**
 * 
 */
package com.suyx.job.utils.mh;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.suyx.job.utils.ImageUtils;
import com.suyx.job.utils.SampleOCRUtil;
import com.suyx.job.utils.ScreenCapture;

import lombok.extern.slf4j.Slf4j;

/**
 * @author syx
 *
 */
@Slf4j
@Component
public class PtsScene {
	private static String SC_PIC_PATH = "H:\\android\\MH\\";//梦幻宝图截图放置路径
	@Autowired
	private WaTuUtils waTuUtils;
	
	public final static Map<String,String> options_x = new HashMap<>();  
	public final static Map<String,String> options_y = new HashMap<>();
	static {  
		options_x.put("0", "700 329");  
		options_x.put("1", "406 222");  
		options_x.put("2", "506 222");
		options_x.put("3", "606 222"); 
		options_x.put("4", "406 322");
		options_x.put("5", "506 322");
		options_x.put("6", "606 322");
		options_x.put("7", "406 422");
		options_x.put("8", "506 422");
		options_x.put("9", "606 422");
		
		options_y.put("0", "841 328");  
		options_y.put("1", "537 230");  
		options_y.put("2", "637 230");
		options_y.put("3", "737 230"); 
		options_y.put("4", "537 330");
		options_y.put("5", "637 330");
		options_y.put("6", "737 330");
		options_y.put("7", "537 430");
		options_y.put("8", "637 430");
		options_y.put("9", "737 430");
	} 
	
	public  void pts(String device ,String zuobiao,String baoguo) throws Exception{
		//打开包裹
		ScreenCapture.mouseClick(device, "1308 675");
		ScreenCapture.mouseClick(device, "730 224");// 打开ca7
		ScreenCapture.mouseClick(device, "522 422");// 使用
		ScreenCapture.mouseClick(device, "277 600");//7到CA到GJ 
		ScreenCapture.mouseClick(device, "1156 52");// 关闭包裹
		ScreenCapture.mouseClick(device, "99 652");// 
		
		//先到达大唐国境
		Thread.sleep(2 * 1000L);
		ScreenCapture.mouseClick(device, "117 68");//打开地图
		ScreenCapture.mouseClick(device, "880 574");// 
		ScreenCapture.mouseClick(device, "1117 48"); //关闭地图
		Thread.sleep(27 * 1000L);
		ScreenCapture.mouseClick(device, "690 246"); //点击传送
		ScreenCapture.mouseClick(device, "1233 338"); //传送
		
	}
	
	public  void ptsCs(String device) throws Exception{
		String path = SC_PIC_PATH + device +"\\";
		while(true){
    		ScreenCapture.mouseClick(device, "1211 682");
            ScreenCapture.mouseClick(device, "1242 587");
            ScreenCapture.mouseClick(device, "1211 682");
    		ScreenCapture.snapshot(device,path, "screen.png");
            ImageUtils.cutPNG(new FileInputStream(path +"screen.png"),
                    new FileOutputStream(path + device +".png"), 93,18,117,35);
            String area = SampleOCRUtil.sampleBasic(path + device +".png");
            if(area.indexOf("普") == -1) {
            	ScreenCapture.mouseClick(device, "1211 682");
                ScreenCapture.mouseClick(device, "1242 587");
                ScreenCapture.mouseClick(device, "1211 682");
            }else{
            	break;
            }
            
    	}  
		
	}
	
	public  void ptsSceneSame(String device,String zuobiao,String baoguo) throws Exception{
		Thread.sleep(2 * 1000L);
		ScreenCapture.mouseClick(device, "117 68");//打开地图
        ScreenCapture.mouseClick(device, "432 107");// 选x坐标
        String x = zuobiao.split(" ")[0];
        String y = zuobiao.split(" ")[1];
        input_x(device,x);
        ScreenCapture.mouseClick(device, "706 422");
        ScreenCapture.mouseClick(device, "567 112"); // 选y坐标
        input_y(device, y);
        ScreenCapture.mouseClick(device, "837 430");
        ScreenCapture.mouseClick(device, "700 117");  // 前往
        ScreenCapture.mouseClick(device, "1139 83"); //关闭地图
        //开始挖图
        waTuUtils.startWatu(device, zuobiao, baoguo);
	}
	
	public  void input_x(String device,String x){
		for(int i =0;i<x.length();i++){
			char c = x.charAt(i);
			String x_zb = options_x.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, x_zb);
		}
	}
	
	public  void input_y(String device,String y){
		for(int i =0;i<y.length();i++){
			char c = y.charAt(i);
			String y_zb = options_y.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, y_zb);
		}
	}
}
